package com.cswangdao.controller.admin;

import com.cswangdao.domain.dto.AdminPageDTO;
import com.cswangdao.domain.model.MarketAdmin;
import com.cswangdao.domain.vo.AdminPageVo;
import com.cswangdao.result.PageResult;
import com.cswangdao.result.Result;
import com.cswangdao.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/admin")
@Slf4j
public class AdminAdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping("/list")
    public Result<PageResult<AdminPageVo>> list(AdminPageDTO pageDTO) {
        log.info("管理员分页查询：{}",pageDTO);
        PageResult<AdminPageVo> pageResult = adminService.pageQueryInfo(pageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/create")
    public Result<MarketAdmin> create(@RequestBody MarketAdmin admin)  {
        log.info("管理员创建：{}", admin);
        adminService.addAdmin(admin);
        return Result.success(admin);
    }

    @PostMapping("/update")
    public Result<MarketAdmin> update(@RequestBody MarketAdmin admin) {
        log.info("管理员更新：{}", admin);
        adminService.updateById(admin);
        return Result.success(admin);
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody MarketAdmin admin)  {
        log.info("管理员删除：{}", admin);
        adminService.deleteById(admin.getId());
        return Result.success();
    }
}
